import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Salta cuerdas y evita peligros
 * 
 * @author Diana Laura Valtierra Franco, Yahir de Jesus Terrones Quiroz
 * @version 5.1
 */
public class MonkeyWorld extends World
{

    /**
     * @param int TAM_X=900;
     * @param int TAM_Y=400;
     * 
     */
    public static final int TAM_X=900;
    public static final int TAM_Y=400;
    private SimpleTimer tiempo;
    private SimpleTimer vidasT;
     private SimpleTimer puntosT;
    private Counter msjReloj;
    private Counter msjVidas;
    private Counter msjPuntos;
    private int scroll=0;
    private GreenfootSound sonido;
   
    //private Portada portada;
    private int tiempoFruta;
    private int velFrutas;
    private boolean entroLevel0;
    private boolean entroLevel1;
    private boolean creoPiso;
    private int nivel;
    private Counter puntos;
    private int numLiana;
    private int numPiso;
    private int numPisoLiana;
    public MonkeyWorld()
    { 
       super(TAM_X,TAM_Y, 1,false);
       setActOrder(fondoImagenes.class,Monkey.class);
       nivel=0;
       //-----------------------------------------------------------
        tiempo=new SimpleTimer();//tiempo
        msjReloj=new Counter("Tiempo:  ");
        msjReloj.setValue(60);//le damos valor inicial de 60 segundos
        //-----------------------------------------------------------
        vidasT=new SimpleTimer();//vidas
        msjVidas=new Counter("Vidas:  ");
        msjVidas.setValue(3);
        //-----------------------------------------------------------
        puntosT=new SimpleTimer();//puntos
        msjPuntos=new Counter("Puntos:  ");
        msjPuntos.setValue(0);
        //-------------------------------------------------------------
       entroLevel0=false;//para checar si entra alos niveles
       entroLevel1=false;
       creoPiso=false;
       tiempoFruta=0;
       numLiana=0;
       numPiso=0;
       numPisoLiana=Greenfoot.getRandomNumber(2);
       sonido = new GreenfootSound("jungla.mp3");
    }
    
    /** 
     * actua del mundo, donde los objetos que tienen un movimiento aleatorio o en cierta posicion se crean.
     */
    public void act()
     {
       //-------------------------------------------------------------
        int numFruta=Greenfoot.getRandomNumber(8);//para que nos de una fruta aleatoriamente
         sonido.playLoop();
        //-----------------------------------------------------------
        
         if(tiempo.millisElapsed()>=1000){
            tiempo.mark();
            msjReloj.add(-1);
            numPiso++;
            if(numPiso==2){
               addObject(new Piso(),getWidth()+getWidth()/4,getHeight()-20);
               numPiso=0;
            }
            
            if(numPiso==1){
              switch(numLiana){
                case 0: addObject(new Liana(),getWidth()+getWidth()/4,getHeight()/2-getHeight()/4);//lianas
                        numLiana=1;
                        break;
                
                case 1: addObject(new Liana2(),getWidth()+getWidth()/4,getHeight()/2-getHeight()/4);//liana
                        numLiana=2;
                        break;
                
                case 2: addObject(new Liana3(),getWidth()+getWidth()/4,getHeight()/2-getHeight()/4);//lianas
                        numLiana=0;
                        break;
               }
            }
            
             if(nivel==1 || nivel==2 || nivel==3){
           
             
               switch(numFruta){
           
                case 1: addObject(new Banana(),getWidth(), Greenfoot.getRandomNumber(getWidth()/2-getWidth()/4) );
                break;
                 
                case 2: addObject(new Pina(),getWidth(),Greenfoot.getRandomNumber(getWidth()/2-getWidth()/4));
                break;
           
                case 3: addObject(new Manzana(),getWidth(),Greenfoot.getRandomNumber(getWidth()/2-getWidth()/4));
                break;     
     
                case 4: addObject(new Mango(),getWidth(),Greenfoot.getRandomNumber(getWidth()/2-getWidth()/4));
                break;
                
                case 5: addObject(new PinaPodrida(),getWidth(),Greenfoot.getRandomNumber(getWidth()/2-getWidth()/4));
                break;
                
                case 6:  addObject(new BananaPodrida(),getWidth(),Greenfoot.getRandomNumber(getWidth()/2-getWidth()/4));
                break;
                
                case 7:  addObject(new ManzanaPodrida(),getWidth(),Greenfoot.getRandomNumber(getWidth()/2-getWidth()/4));
                break;
                
                case 8: addObject(new MangoPodrido(),getWidth(),Greenfoot.getRandomNumber(getWidth()/2-getWidth()/4));
                break;
                
                }
                velFrutas=0;
              }
              
            
          }
          
          
        //------------------------------------------------ NIVELES------------------------------------------------------------
        if(nivel==0 && entroLevel0==false){
             addObject(new Fondo(),300,300);
             addObject(new botonPlay(),getWidth()-getWidth()/6,getHeight()/4);
             addObject(new botonControles(),getWidth()-getWidth()/6,getHeight()/2);
             addObject(new botonAyuda(),getWidth()-getWidth()/6,getHeight()/2+getHeight()/4);
             entroLevel0=true;//para que solo lo aga una vez
        }
        
        if(nivel==1 && entroLevel1==false){
          addObject(new Monkey(),getWidth()/2-getWidth()/4,getHeight()/2+getHeight()/4);//monkey
          addObject(new Piso(),getWidth()/2-getWidth()/4,getHeight()-20);//piso abajo del gorila
          addObject(msjVidas,100,30);
          addObject(msjReloj,220,30);
          addObject(msjPuntos,340,30);
          entroLevel1=true;//pra que solo lo aga una vez
        }
      
    }
    
    /**
     * @param int unscroll
     */
    public void setScroll(int unscroll)
    {
      this.scroll=unscroll;
    }
    
    /**
     * @param int dif
     */
    public void changeScroll(int dif)
    {
        scroll+=dif;
    }
    
    /**
     * @return int scroll
     */
    public int getScroll()
    {
        return scroll;
    }
    
    /** 
     * metodo donde me regresa el nivel y poder acceder a el porque es privado
     * 
     * @return int nivel
     */
    public int getNivel()
    {
        return nivel;
    }
    
    //-----------------------------------------------------
    public Counter getPuntos()
    {
        return msjPuntos;
    }
    
    public Counter getVidas()
    {
        return msjVidas;
    }
    
    //-----------------------------------------------------
    /*
    public Portada getPortada()
    {
        return portada;
    }*/
    
    /**
     *  metodo para cambiar el nivel al interactuar con el menu 
     */
     public void cambiaNivel()
    {
       GreenfootImage imagen;
       
        switch(nivel)
        {
           case 1 :removeObjects(getObjects(Portada.class));
                   tiempo.mark();
                   break;
        }   
        nivel++;
    }
    
     public void stopped() 
    {
     super.stopped(); 
     sonido.pause();
    }
}
